﻿Module NoGenerater
    Public Function GenerateNewReservationNo() As String

        Dim obj As Object = cmd.ExecuteScalar("SELECT MAX(ReservationNo) from Reservation;")

        Dim lastNo As String
        If obj Is DBNull.Value Then
            lastNo = "RES-0000000"
        Else
            lastNo = obj.ToString()
        End If

        ' PUC-000031
        lastNo = lastNo.Replace("RES-", "")
        ' 000031
        Dim nextNo As Int16 = Convert.ToInt16(lastNo) + 1
        ' 32
        Dim result = "RES-" & nextNo.ToString("0000000")
        Return result

    End Function

    Public Function GenerateNewChecinNo() As String

        Dim obj As Object = cmd.ExecuteScalar("SELECT MAX(CheckInNo) from CheckIn;")

        Dim lastNo As String
        If obj Is DBNull.Value Then
            lastNo = "CIN-0000000"
        Else
            lastNo = obj.ToString()
        End If

        ' PUC-000031
        lastNo = lastNo.Replace("CIN-", "")
        ' 000031
        Dim nextNo As Int16 = Convert.ToInt16(lastNo) + 1
        ' 32
        Dim result = "CIN-" & nextNo.ToString("0000000")
        Return result

    End Function

    Public Function GenerateNewPaymentNo() As String

        Dim obj As Object = cmd.ExecuteScalar("SELECT MAX(PaymentNo) from Payment;")

        Dim lastNo As String
        If obj Is DBNull.Value Then
            lastNo = "PAY-0000000"
        Else
            lastNo = obj.ToString()
        End If

        ' PUC-000031
        lastNo = lastNo.Replace("PAY-", "")
        ' 000031
        Dim nextNo As Int16 = Convert.ToInt16(lastNo) + 1
        ' 32
        Dim result = "PAY-" & nextNo.ToString("0000000")
        Return result

    End Function
End Module
